package com.hyphenate.easeui.widget.chatrow;

import android.content.Context;
import android.view.View;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.hyphenate.chat.EMMessage;
import com.hyphenate.easeui.R;
import com.hyphenate.easeui.utils.EaseUserUtils;

/**
 * Created by e on 2017/8/20.
 */

public class EaseChatShareLocation extends EaseChatRow{

    private String from;

    private TextView contentView;
    public EaseChatShareLocation(Context context, EMMessage message, int position, BaseAdapter adapter) {
        super(context, message, position, adapter);
        from = context.getResources().getString(R.string.consult_sharing_location_from);
    }

    @Override
    protected void onInflateView() {
        inflater.inflate(message.direct() == EMMessage.Direct.RECEIVE ?
                R.layout.ease_row_received_share_location : R.layout.ease_row_sent_share_location, this);
    }

    @Override
    protected void onFindViewById() {
        contentView = (TextView) findViewById(R.id.tv_chatcontent);
    }

    @Override
    protected void onUpdateView() {
        adapter.notifyDataSetChanged();
    }

    @Override
    protected void onSetUpView() {

        if (message.direct() == EMMessage.Direct.SEND) {
            contentView.setText(R.string.consult_sharing_location_to);

            setMessageSendCallback();
            switch (message.status()) {
                case CREATE:
                    progressBar.setVisibility(View.GONE);
                    statusView.setVisibility(View.VISIBLE);
                    break;
                case SUCCESS:
                    progressBar.setVisibility(View.GONE);
                    statusView.setVisibility(View.GONE);
                    break;
                case FAIL:
                    progressBar.setVisibility(View.GONE);
                    statusView.setVisibility(View.VISIBLE);
                    break;
                case INPROGRESS:
                    progressBar.setVisibility(View.VISIBLE);
                    statusView.setVisibility(View.GONE);
                    break;
                default:
                    break;
            }


        }else {
            try {
                if (mReceiver !=null){
                    contentView.setText(String.format(from,mReceiver.username));
                }else if (EaseUserUtils.getUserInfo(message.getFrom()) !=null){
                    String username = EaseUserUtils.getUserInfo(message.getFrom()).getUsername();
                    contentView.setText(String.format(from,username));
                }

            }catch (Exception e){
                contentView.setText(String.format(from,"wedo"));
            }
        }
    }

    @Override
    protected void onBubbleClick() {

    }
}
